const events = require("events");
const EventEmitter = events.EventEmitter;

//dog的构造函数
function Radio(radioName, times) {
    //构造函数对象添加属性
    this.radioName = radioName;
    this.times = times;
    //执行EventEmitter函数，调用主体是this
    EventEmitter.call(this);
    this.on("play", () => {
        console.log(this.radioName + " " + this.times + " opened")
        let timeOutId = setTimeout(() => {
            console.log("lalala...");
            this.emit("stop");
        }, 2000)
    })
    this.on("stop", () => {
        console.log(this.radioName + " " + this.times + " closed");
        process.exit();
    })
}

Radio.prototype = EventEmitter.prototype;
let radio = new Radio("music radio", "FM 106.7");
radio.emit("play");
